﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Contacto
{
    public partial class ver : Form
    {
        public ver()
        {
            InitializeComponent();
        }

        private void brn_Cancelar_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btn_Abrir_Click(object sender, EventArgs e)
        {
            if (tx_name.Text != " " && tx_name.Text != "")
            {
                string nombre = tx_name.Text;
                string r_name = @"Contactos\\" + nombre + "\\name", r_last = @"Contactos\\" + nombre + "\\lastname", r_day = @"Contactos\\" + nombre + "\\day", r_mes = @"Contactos\\" + nombre + "\\mes", r_year = @"Contactos\\" + nombre + "\\year", r_phone = @"Contactos\\" + nombre + "\\phone", r_mail = @"Contactos\\" + nombre + "\\mail", r_address = @"Contactos\\" + nombre + "\\address";
                if (System.IO.File.Exists(r_name))
                {
                    string w_name, w_lastname, w_day, w_mes, w_year, w_phone, w_mail, w_address;

                    System.IO.StreamReader temp0 = new System.IO.StreamReader(r_name);
                    w_name = temp0.ReadToEnd();
                    temp0.Close();
                    System.IO.StreamReader temp1 = new System.IO.StreamReader(r_last);
                    w_lastname = temp1.ReadToEnd();
                    temp1.Close();
                    System.IO.StreamReader temp2 = new System.IO.StreamReader(r_day);
                    w_day = temp2.ReadToEnd();
                    temp2.Close();
                    System.IO.StreamReader temp3 = new System.IO.StreamReader(r_mes);
                    w_mes = temp3.ReadToEnd();
                    temp3.Close();
                    System.IO.StreamReader temp4 = new System.IO.StreamReader(r_year);
                    w_year = temp4.ReadToEnd();
                    temp4.Close();
                    System.IO.StreamReader temp5 = new System.IO.StreamReader(r_phone);
                    w_phone = temp5.ReadToEnd();
                    temp5.Close();
                    System.IO.StreamReader temp6 = new System.IO.StreamReader(r_mail);
                    w_mail = temp6.ReadToEnd();
                    temp6.Close();
                    System.IO.StreamReader temp7 = new System.IO.StreamReader(r_address);
                    w_address = temp7.ReadToEnd();
                    temp7.Close();
                    tx_lastname.Text = w_lastname;
                    tx_day.Text = w_day;
                    tx_mes.Text = w_mes;
                    tx_year.Text = w_year;
                    tx_phone.Text = w_phone;
                    tx_mail.Text = w_mail;
                    tx_address.Text = w_address;
                }
                else
                {
                    MessageBox.Show("No existe ese contacto", "Aviso de error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    tx_name.Text = "";
                }
            }
        }
    }
}
